<?php


/**
 * Radcodes - SocialEngine Module
 *
 * @category   Application_Extensions
 * @package    Badge
 * @copyright  Copyright (c) 2009-2010 Radcodes LLC (http://www.radcodes.com)
 * @license    http://www.radcodes.com/license/
 * @version    $Id$
 * @author     Vincent Van <vincent@radcodes.com>
 */
 
 
?>
<script type="text/javascript">

var currentOrder = '<?php echo $this->order ?>';
var currentOrderDirection = '<?php echo $this->order_direction ?>';
var changeOrder = function(order, default_direction){
  // Just change direction
  if( order == currentOrder ) {
    $('order_direction').value = ( currentOrderDirection == 'ASC' ? 'DESC' : 'ASC' );
  } else {
    $('order').value = order;
    $('order_direction').value = default_direction;
  }
  $('filter_form').submit();
}


  en4.core.runonce.add(function(){$$('th.admin_table_short input[type=checkbox]').addEvent('click', function(){ $$('input[type=checkbox]').set('checked', $(this).get('checked', false)); })});

  var delectSelected =function(){
    var checkboxes = $$('input[type=checkbox]');
    var selecteditems = [];

    checkboxes.each(function(item, index){
      var checked = item.get('checked', false);
      var value = item.get('value', false);
      if (checked == true && value != 'on'){
        selecteditems.push(value);
      }
    });

    $('ids').value = selecteditems;
    $('delete_selected').submit();
  }

</script>

<h2><?php echo $this->translate("Badges Plugin") ?></h2>

<?php if( count($this->navigation) ): ?>
  <div class='tabs'>
    <?php
      // Render the menu
      //->setUlClass()
      echo $this->navigation()->menu()->setContainer($this->navigation)->render()
    ?>
  </div>
<?php endif; ?>

<p>
  <?php echo $this->translate("This page allows to you manage badges which can be assigned to your members. Entering criteria into the filter fields will help you find specific badges. Leaving the filter fields blank will show all the badges on your social network.") ?>
</p>
<br />

<div>
    <?php echo $this->htmlLink($this->url(array('action'=>'create')), 
      $this->translate('Create New Badge'),
      array('class' => 'buttonlink icon_badge_create')
    )?> 
</div>
<br />

<div class='admin_search'>
  <?php echo $this->formFilter->render($this) ?>
</div>

<br />



<?php if( count($this->paginator) ): ?>

<div class='admin_results'>
  <div>
    <?php $badgeCount = $this->paginator->getTotalItemCount() ?>
    <?php echo $this->translate(array("%s badge found", "%s badges found", $badgeCount), ($badgeCount)) ?>
  </div>
  <div>
    <?php // echo $this->paginationControl($this->paginator, null, null, array('params'=>$this->params)); ?>
    
    <?php echo $this->paginationControl($this->paginator, null, null, array(
      'query' => $this->formValues
    )); ?>  
    
  </div>
</div>
<br />

<table class='admin_table'>
  <thead>
    <tr>
      <th class='admin_table_short'><a href="javascript:void(0);" onclick="javascript:changeOrder('badge_id', 'DESC');">ID</a></th>
      <th><?php echo $this->translate('Photo');?></th>
      <th><a href="javascript:void(0);" onclick="javascript:changeOrder('title', 'ASC');"><?php echo $this->translate("Title") ?></a></th>
      <th width="125"><?php echo $this->translate('Assignment Type');?></th>
      <th><?php echo $this->translate('Member Count')?></th>
      <th><?php echo $this->translate('Category');?></th>
      <th><?php echo $this->translate("Options") ?></th>
    </tr>
  </thead>
  <tbody>
    <?php foreach ($this->paginator as $item): // $this->string()->chunk($item->getTitle(), 5) ?>
      <tr>
        <td><?php echo $item->badge_id ?></td>
        <td><?php echo $this->htmlLink(
            array('route' => 'admin_default', 'module' => 'badge', 'controller' => 'manage', 'action' => 'photo', 'badge_id' => $item->badge_id),
            $this->itemPhoto($item, 'thumb.icon'),
            array('class' => 'smoothbox')) ?>
        </td>    
        <td><?php echo $this->htmlLink($item->getHref(), $item->getTitle(), array('target'=>'_blank'))?>
          <br /><span class="badge_description"><?php echo $this->viewMore($item->getDescription());?></span>
        </td>
        <td>
          <?php if ($item->isMembershipTypeMapping()): ?>
            <?php echo $this->translate('Mapping (Automatic)'); ?>
          <?php elseif ($item->isMembershipTypeAward()): ?>
            <?php echo $this->translate('Award (Manual)'); ?>
            <br />
            <?php echo $this->htmlLink(
              array('route' => 'admin_default', 'module' => 'badge', 'controller' => 'awards', 'action' => 'create', 'badge_id' => $item->badge_id),
              $this->translate("add member")) ?>
            <br />
            <?php echo $this->htmlLink(array('route' => 'admin_default', 'module' => 'badge', 'controller' => 'awards', 'badge' => $item->badge_id), $this->translate("awards")) ?>
            |
            <?php echo $this->htmlLink(array('route' => 'admin_default', 'module' => 'badge', 'controller' => 'requests', 'badge' => $item->badge_id), $this->translate("requests")) ?>

          <?php else: ?>  
            <?php echo $this->translate('ERROR'); ?>
          <?php endif; ?>
        </td>
        <td>
          <?php echo $item->membershipCount(); ?>
        </td>
        <td><?php echo $this->htmlLink($item->getCategory()->getHref(), $item->getCategory()->getTitle(), array('target'=>'_blank'))?></td>
        <td>
          <?php echo $this->htmlLink(
            array('route' => 'admin_default', 'module' => 'badge', 'controller' => 'manage', 'action' => 'edit', 'badge_id' => $item->badge_id),
            $this->translate("edit"),
            array('class' => '')) ?>
          |
          <?php echo $this->htmlLink(
            array('route' => 'admin_default', 'module' => 'badge', 'controller' => 'manage', 'action' => 'delete', 'badge_id' => $item->badge_id),
            $this->translate("delete"),
            array('class' => 'smoothbox')) ?>
        </td>
      </tr>
    <?php endforeach; ?>
  </tbody>
</table>

<br />


<?php //print_r($this->params)?>
<?php else:?>
  <div class="tip">
    <span>
      <?php echo $this->translate("There are no badges posted yet.") ?>
    </span>
  </div>
<?php endif; ?>

